package com.zrk.base;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 数组学习
 * @author zrk
 * @version 1.0
 */
public class ArrayLearn {
    public static void main(String[] args) {
        int opt = 3;
        double arrDouble[] = {1.0, 2.0, 3.0};

        switch (opt) {
            case 1 -> switchOne();
            case 2 -> ArrayLearn.printArrayForEach(arrDouble);
            case 3 -> ArrayLearn.ArrayToString(arrDouble);
        }
    }

    /**
     * 1.读取5个double并输出
     */
    private static void switchOne() {
        Scanner scanner = new Scanner(System.in);
        double arrDouble5[] = new double[5];
        for (int i = 0; i < arrDouble5.length; i++) {
            arrDouble5[i] = scanner.nextDouble();
        }

        ArrayLearn arrayLearn = new ArrayLearn();
        arrayLearn.printArrayDouble(arrDouble5);
    }

    void printArrayDouble(double arrDouble[]) {
        for (int j = 0 ; j < arrDouble.length; j++) {
            System.out.print(arrDouble[j] + " ");
        }
        System.out.println();
    }

    /**
     * For Each 循环方式
     * @param arrayDouble
     */
    static void printArrayForEach(double arrayDouble[]) {
        for (double d : arrayDouble) {
            System.out.print(d + " ");
        }
    }

    static void ArrayToString(double arrayDouble[]) {
        System.out.println(Arrays.toString(arrayDouble));
    }
}
